#include "SpaceGameScreen.hpp"
#include "../LookAtMatrix.hpp"
#include "../SceneManager.hpp"
#include "../InputManager.hpp"
#include "../Entities/SphereEntity.hpp"
#include "../Entities/TeapotEntity.hpp"
#include "../Entities/Entity3D.hpp"
#include "../Entities/LightShip.hpp"
#include "../Entities/PlayerEntity.hpp"
#include "../Camera/CameraObject.hpp"
#include "../Camera/CameraManager.hpp"
#include "../Particles/EmitterManager.hpp"
#include "../Particles/BaseEmitter.hpp"
#include "../Entities/MaskedSprite.hpp"
#include "../ResourceManagers/TextureObject.hpp"
#include "../ResourceManagers/textfile.h"
#include "../Entities/GameLevel.hpp"

#include <assert.h>

#include "../HDRDemoConstants.hpp"

SpaceGameScreen::SpaceGameScreen() :
m_camera( NULL )
{
	//! Set type of screen.
	m_type = SCREEN_SCENE;
		
	m_camera = new CameraObject( MVector3D( 0.0f, 0.0f, 0.0f ), MVector3D( 0.0f, 0.0f, -1.0f ),
							MVector3D( 1.0f, 0.0f, 0.0f ), MVector3D( 0.0f, 20.0f, 0.0f ), 
							45.0, 1.0, 100.0 );

	CameraManager::GetInstance()->RegisterCamera( m_camera );

	//! Set m_camera2 as active camera (scene will be rendered from its point of view).
	m_camera->ActivateCamera();

	//! Initialize entities for this scene.
	InitializeEntities();

	glClearColor(0.4f, 0.4f, 0.4f, 0.0f);
}

SpaceGameScreen::~SpaceGameScreen()
{
	//! Unregister cameras so they can be destroyed.
	CameraManager::GetInstance()->UnregisterAllCameras();
}

bool SpaceGameScreen::InitializeEntities()
{
	m_pLevel = new GameLevel("level.lvf", 0.0f);
	PlayerEntity* pPlayer = new PlayerEntity("playerShip.gmf", "stripes.bmp", 0.0, MVector3D(1.0f, 5.0f, 5.0f));
	SceneManager::GetInstance()->setPlayer(pPlayer);
	SceneManager::GetInstance()->RegisterEntity(pPlayer);
	InputManager::getInstance()->registerListener(pPlayer, KEYBOARD_EVENT_T);

	/*
	LightShip* pBuilding = new LightShip("building_1.gmf", "stripes.bmp");
	pBuilding->setPosition(MVector3D(1.0, 0.0, -5.0));
	pBuilding->setFlySpeed(1.0f);
	SceneManager::GetInstance()->RegisterEntity(pBuilding);

	LightShip* pShip1 = new LightShip("lightShip_1.gmf", "stripes.bmp");
	pShip1->setPosition(MVector3D(-2.0, 5.0, -10.0));
	pShip1->setFlySpeed(2.0f);
	SceneManager::GetInstance()->RegisterEntity(pShip1);

	LightShip* pShip2 = new LightShip("lightShip_1.gmf", "bzdet.bmp");
	pShip2->setPosition(MVector3D(0.0, 5.0, -7.0));
	pShip2->setFlySpeed(2.0f);
	SceneManager::GetInstance()->RegisterEntity(pShip2);*/

	//AnimatedSprite *ex1;
	////MaskedSprite* ms1;

	//ex1 = new AnimatedSprite("expl2.png",11,75, MVector3D(0.5, 5.0, 5.0), true, 1.0);
	//SceneManager::GetInstance()->RegisterEntity( ex1 );

	////ms1 = new MaskedSprite("msprite.png", "mask.png", MVector3D(0.0, 0.0, 0.0), TEXTURE_STANDARD, 3.0);
	////SceneManager::GetInstance()->RegisterEntity( ms1 );

	////BaseEmitter* bEmitter = new BaseEmitter("fx_med.png", 250, 250);
	////EmitterManager::GetInstance()->AddEmitter(bEmitter);

	return true;
}

bool SpaceGameScreen::CleanUpEntities()
{
	SceneManager::GetInstance()->UnregisterAllEntities();

	return true;
}

//EOF
